<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<%@ include file="/static/commons/jquery-easyui.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
	 <title>${title }</title>
	 <link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css"></link>
	 <link rel="stylesheet" href="${ctx }/static/styles/frame/backstage.css"></link>
	 <script type="text/javascript" src="${ctx}/static/scripts/util.js"></script>
	 <script type="text/javascript" src="${ctx}/static/scripts/common.js"></script>
  </head>
  <body class="easyui-layout"  id="main_layout_xx" style="overflow: hidden;">
	<div data-options="region:'north',border:false" style="height:101px;overflow: hidden;" > 
		<jsp:include page="top.jsp"></jsp:include>
	</div>
	<div data-options="region:'west',split:false,border:false" style="width:150px;overflow:hidden;" id="menuDiv" >
		<div class="main">
			<div class="f_l" id="westMenuDiv">
			</div>
		</div>
	</div>
	<div data-options="region:'center',border:false" >
			 <div id="tabs" class="easyui-tabs window_tabs" fit="true" border="false">   
				<div title="首页" style="overflow:hidden;" id="action_center">
					<div style="height: 100%;" id="indexDiv" >
						<iframe scrolling="auto" frameborder="0" src="${ctx }/frameIndex/workspace" id="mainFrame"
						 name="mainFrame" style="width:100%; height:100%;"></iframe>
					</div>
				</div>
       		</div>
	</div>
	<!-- 右键菜单 -->
    <div id="mm" class="easyui-menu cs-tab-menu" style="display: none;">
		<div id="mm-tabupdate">刷新</div>
		<div class="menu-sep"></div>
		<div id="mm-tabclose">关闭</div>
		<div id="mm-tabcloseother">关闭其他</div>
		<div id="mm-tabcloseall">关闭全部</div>
	</div>
	<script type="text/javascript" src="${ctx}/static/scripts/dialog.js"></script>
	<script type="text/javascript" src="${ctx}/static/scripts/alert.js"></script>
  </body>
  <script type="text/javascript">
  	setBasePath("${ctx}");
	var defTabName = "首页";
	function addTab(title, url, menuId){
		console.log("url="+url+"\t"+title+"\t"+menuId);
		if ($('#tabs').tabs('exists', title)){
			$('#tabs').tabs('select', title);//选中并刷新
			var currTab = $('#tabs').tabs('getSelected');
			if(url != undefined && currTab.panel('options').title != defTabName) {
				$('#tabs').tabs('update',{
					tab:currTab,
					options:{
						content:createFrame(url, menuId)
					}
				})
			}
		} else {
			var content = createFrame(url, menuId);
			$('#tabs').tabs('add',{
				title:title,
				content:content,
				closable:true
			});
		}
		tabClose();
	}
	function createFrame(url, menuId) {
		if(isEmpty(menuId)){
			try{
				menuId = url.substring(url.indexOf("menuId=") + 7);
			}catch(e){}
		}
		var s = '<iframe scrolling="auto" frameborder="0" id="tabFrame'+ menuId +'" src="'+url+'" style="width:100%;height:100%;"></iframe>';
		return s;
	}
	function tabClose() {
			/*双击关闭TAB选项卡*/
			$(".tabs-inner").dblclick(function(){
				var subtitle = $(this).children(".tabs-closable").text();
				$('#tabs').tabs('close',subtitle);
			})
			/*为选项卡绑定右键*/
			$(".tabs-inner").bind('contextmenu',function(e){
				$('#mm').menu('show', {
					left: e.pageX,
					top: e.pageY
				});
		
				var subtitle =$(this).children(".tabs-closable").text();
		
				$('#mm').data("currtab",subtitle);
				$('#tabs').tabs('select',subtitle);
				return false;
			});
		}		
		//绑定右键菜单事件
		function tabCloseEven() {
			//刷新
			$('#mm-tabupdate').click(function(){
				var currTab = $('#tabs').tabs('getSelected');
				var url = $(currTab.panel('options').content).attr('src');
				if(url != undefined && currTab.panel('options').title != defTabName) {
					$('#tabs').tabs('update',{
						tab:currTab,
						options:{
							content:createFrame(url)
						}
					})
				}
			})
			//关闭当前
			$('#mm-tabclose').click(function(){
				var currtab_title = $('#mm').data("currtab");
				$('#tabs').tabs('close',currtab_title);
			})
			//全部关闭
			$('#mm-tabcloseall').click(function(){
				$('.tabs-inner span').each(function(i,n){
					var t = $(n).text();
					if(t != defTabName) {
						$('#tabs').tabs('close',t);
					}
				});
			});
			//关闭除当前之外的TAB
			$('#mm-tabcloseother').click(function(){
				var prevall = $('.tabs-selected').prevAll();
				var nextall = $('.tabs-selected').nextAll();		
				if(prevall.length>0){
					prevall.each(function(i,n){
						var t=$('a:eq(0) span',$(n)).text();
						if(t != defTabName) {
							$('#tabs').tabs('close',t);
						}
					});
				}
				if(nextall.length>0) {
					nextall.each(function(i,n){
						var t=$('a:eq(0) span',$(n)).text();
						if(t != defTabName) {
							$('#tabs').tabs('close',t);
						}
					});
				}
				return false;
			});
			//关闭当前右侧的TAB
			$('#mm-tabcloseright').click(function(){
				var nextall = $('.tabs-selected').nextAll();
				if(nextall.length==0){
					//msgShow('系统提示','后边没有啦~~','error');
					alert('后边没有啦~~');
					return false;
				}
				nextall.each(function(i,n){
					var t=$('a:eq(0) span',$(n)).text();
					$('#tabs').tabs('close',t);
				});
				return false;
			});
			//关闭当前左侧的TAB
			$('#mm-tabcloseleft').click(function(){
				var prevall = $('.tabs-selected').prevAll();
				if(prevall.length==0){
					alert('到头了，前边没有啦~~');
					return false;
				}
				prevall.each(function(i,n){
					var t=$('a:eq(0) span',$(n)).text();
					$('#tabs').tabs('close',t);
				});
				return false;
			});
		
			//退出
			$("#mm-exit").click(function(){
				$('#mm').menu('hide');
			})
		}
	$(document).ready(function(){
  		$(window).resize(function(){
  			var width = $(window).width();
  			if(width < 1000){
  				$(window).width(1000)
  			}
  		});
  		tabCloseEven();
		$('#mm').css("display","none");
		$.parser.parse('#main_layout_xx');
		initCss();
	});
	
	function initCss(){
		$('.main .f_l').css('background','#525252');
		$('#menuDiv').css('background','#525252');
		$('#menuDiv').css('border-right','1px solid #525252');
	}
 </script>
</html>
